import { fileURLToPath, URL } from 'url'
import styleImport, { VantResolve } from 'vite-plugin-style-import';
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { svgBuilder } from './src/plugins/svgBuilder';
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';
import AutoImport from 'unplugin-auto-import/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';


// https://vitejs.dev/config/
export default defineConfig(({ mode, command }) => {
  const env = loadEnv(mode, process.cwd())
  return {
    base: '/',
    plugins: [
      vue(),
      styleImport({
        resolves: [VantResolve()],
      }),
      Components({
        resolvers: [VantResolver()],
      }),
      svgBuilder('./src/assets/icons/svg/'),
      AutoImport({
        imports: [
          'vue',
          'vue-router', // 如果需要路由相关自动引入
          'pinia',
        ],
        dts: true, // 生成自动导入的 TypeScript 声明文件
        eslintrc: {
          enabled: true, // 生成 eslint 配置
        },
        resolvers: [ElementPlusResolver()]
      }),
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    server: {
      proxy: {
        '/dev-api': {
          // target: 'https://liveback.qiuxuemao.cn', // wz
          // target: ' http://139.9.106.21:20682', // wz
          target: 'http://192.168.0.154:10001/',  //xusd
          // target: 'http://192.168.0.155:10001/',  //ws
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/dev-api/, '')
        }
      }
    }
  }
})
